package com.demo.security.access.impl;

import java.util.Collection;
import java.util.List;

import org.aopalliance.intercept.MethodInvocation;
import org.springframework.security.core.Authentication;

import com.demo.security.access.AccessLogicInvocation;
import com.demo.security.access.AfterLogicInvocation;
import com.demo.security.access.LogicAttribute;

/**
 * 方法调用的后置拦截处理管理对象实现
 * 
 * 主要针对带有LogicAttribute属性的方法调用时的处理
 * @author ryuu.kk
 *
 */
public class AfterLogicInvocationManagerImpl extends AbstractAfterLogicManager<MethodInvocation> {

	public AfterLogicInvocationManagerImpl(List<AfterLogicInvocation<MethodInvocation>> afterInvocations) {
		super(afterInvocations);
	}

	@Override
	public Object access(Authentication authentication, Object object, Collection<LogicAttribute> logicAttributes, Object returnObject) {
		
		if (getAfterInvocations() != null) {
			for (AfterLogicInvocation<MethodInvocation> invoke : getAfterInvocations()) {
				// 取得所有访问逻辑调用对象,进行处理
				if (invoke.supports(object.getClass())) {
					invoke.after(authentication, (MethodInvocation) object, logicAttributes, returnObject);
					if (logger.isDebugEnabled()) {
		                logger.debug("logic : " + invoke + " invoded; ");
		            }
				}
			}
		}
		return returnObject;
	}
}
